package com.basker.pisces.utils;

import com.basker.pisces.exception.ExceptionFactory;

public class ClassUtils {

    public static Class<?> getClass(String className) {
        return getClass(className, true);
    }

    public static Class<?> getClass(String className, boolean throwError) {
        return getClass(className, null, throwError);
    }

    public static Class<?> getClass(String className, ClassLoader classLoader) {
        return getClass(className, classLoader, true);
    }

    public static Class<?> getClass(String className, ClassLoader classLoader, boolean throwError) {
        try {
            return org.springframework.util.ClassUtils.forName(className, classLoader);
        } catch (ClassNotFoundException e) {
            if (throwError) {
                throw ExceptionFactory.createRuntimeException(e);
            }

            return null;
        }
    }

    public static String getPackageName(Class<?> clazz) {
        return org.springframework.util.ClassUtils.getPackageName(clazz);
    }

    public static String getPackageName(String className) {
        return org.springframework.util.ClassUtils.getPackageName(className);
    }
}
